<template>
	<view>
		<rich-text :nodes="content"></rich-text>

		<uni-goods-nav class="footer" :options="options" :fill="true" :button-group="buttonGroup" @click="onClick" @buttonClick="buttonClick" />
		
	<!-- 	options是左边的 图标数据 
		button-group是右边的按钮数据
		都定义在data里 -->
		<!-- @click="onClick" click事件点击的是左边的图标 -->
		<!-- @buttonClick="buttonClick"  点击的是右边的按钮 -->
		<!-- 这两个事件都有一个参数index 就知道现在点的是第几个 -->
		
	</view>
</template>

<script>
import { getDetail } from '../../request/api.js';
export default {
	data() {
		return {
			content: '',
			info:"",
			options: [
				{
					icon: 'headphones',
					text: '客服'
				},
				{
					icon: 'shop',
					text: '店铺',
					info: 2,
					infoBackgroundColor: '#007aff',
					infoColor: 'red'
				},
				{
					icon: 'cart',
					text: '购物车',
					info: 2
				}
			],
			buttonGroup: [
				{
					text: '加入购物车',
					backgroundColor: '#ff0000',
					color: '#fff'
				},
				{
					text: '立即购买',
					backgroundColor: '#ffa200',
					color: '#fff'
				}
			],
			shopcar:uni.getStorageSync("shopcar")||[]
		};
	},
	methods: {
		buttonClick(e){
			console.log(e)
			if(e.index==0){
				let flag=false
				this.shopcar.forEach(item=>{
					if(item.goods_id==this.info.goods_id){
						flag=true
					}
				})
				if(flag==false){
					this.info.num=1;
					this.info.status=false
					this.shopcar.push(this.info)
				}
				uni.setStorageSync("shopcar",this.shopcar)
			}
			
		},
		onClick(e){
			if(e.index==2){
				uni.switchTab({
					url:"/pages/shopcar/shopcar"
				})
			}
			
		}
		
	},
	onLoad(options) {
		console.log(options);
		getDetail(options).then(res => {
			console.log(res);
			this.content = res.message.goods_introduce;
			this.info=res.message
		});
	}
};
</script>

<style lang="scss" scoped>
	.footer{
		width: 100%;
		position: fixed;
		bottom: 0;
		left: 0;
	}
	
</style>
